from matplotlib import pyplot as plt
from matplotlib import font_manager

plt.rcParams['font.sans-serif']=['SimHei']#显示中文标签
plt.rcParams['axes.unicode_minus']=False
my_font=font_manager.FontProperties(fname="C:\Windows\Fonts\simsun.ttc")

x = range(11,31)
y = [1,0,1,1,2,4,3,2,3,4,4,5,6,5,4,3,3,1,1,1]
y1 = [1,0,3,1,2,2,3,3,2,1,2,1,1,1,1,1,1,1,1,1]
fig=plt.figure(figsize=(20,8),dpi=80)

plt.plot(x,y,label="自己",color="blue",linestyle=":")# :表示纯虚线
plt.plot(x,y1,label="同桌",color="cyan",linestyle="--")

_x=x
_xtick_lables=["{}岁".format(i) for i in x]
plt.xticks(_x,_xtick_lables,fontproperties=my_font)
plt.yticks(range(0,9))

#绘制网格
plt.grid(alpha=0.4,linestyle=":")#alpha:透明度

#添加图例
plt.legend(prop=my_font,loc=0)  #loc:图例位置

#添加水印
fig.text(0.4,0.4,"Hello Word",fontsize=60,color="gray",alpha=0.4)

plt.xlabel("年龄(岁)",fontproperties=my_font)
plt.ylabel("数量",fontproperties=my_font)
plt.title("女(男)朋友数量",fontsize=20,fontproperties=my_font)
plt.show()